import type { VbenFormProps, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { ref } from 'vue';
import { queryPage } from './api';

// 操作id
export const idKey = ref('htmlId');
export const handleId = ref('');

// 表格表单数据
export const formOptions: VbenFormProps = {
  schema: [
    {
      component: 'Input',
      defaultValue: undefined,
      fieldName: 'htmlTitle',
      label: '标题',
    },
  ],
  wrapperClass: 'grid-cols-5',
  showCollapseButton: false,
};

// 表格数据
export const gridOptions: VxeTableGridOptions = {
  rowConfig: {
    height: 50,
  },
  columns: [
    { title: '序号', type: 'seq', width: 80 },
    { title: '名称', align: 'left', field: 'htmlTitle' },
    { title: '发布时间', field: 'createTime', width: 200 },
    {
      fixed: 'right',
      slots: { default: 'action' },
      title: '操作',
      width: 160,
    },
  ],
  minHeight: '100%',
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        let params = {
          page: page.currentPage,
          limit: page.pageSize,
          handlerName: 'baseHtml2ListHandler',
          ...formValues,
        };
        return await queryPage(params);
      },
    },
    response: {
      result: 'data.records',
      total: 'data.total',
      list: 'data.records',
    },
  },
  pagerConfig: {
    enabled: true,
    pageSize: 10,
  },
  toolbarConfig: {
    custom: true,
    export: false,
    import: false,
    refresh: true,
    zoom: true,
  },
};

// 编辑弹窗表单配置
export const drawerFormSchema: VbenFormSchema[] = [
  {
    component: 'Input',
    defaultValue: '',
    fieldName: idKey.value,
    label: 'id',
    dependencies: {
      show() {
        return false;
      },
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '名称',
      allowClear: true,
    },
    fieldName: 'htmlTitle',
    label: ' 名称',
    rules: 'required',
  },
  {
    component: 'TinymceEditor',
    fieldName: 'htmlContent',
    label: '内容',
    rules: 'required',
  },
];
